home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 2.iso / STUTTGART / UTIL / SCREEN / CURSES01 / minix / c / charadd < prev    next >
Text File  |  1991-05-05  |  5KB  |  171 lines

  1. /****************************************************************/
  2. /* Addch() routines of the PCcurses package            */
  3. /*                                */
  4. /****************************************************************/
  5. /* This version of curses is based on ncurses, a curses version    */
  6. /* originally written by Pavel Curtis at Cornell University.    */
  7. /* I have made substantial changes to make it run on IBM PC's,    */
  8. /* and therefore consider myself free to make it public domain.    */
  9. /*        Bjorn Larsson (...mcvax!enea!infovax!bl)    */
  10. /****************************************************************/
  11. /* 1.0:    Release:                    870515    */
  12. /****************************************************************/
  13. /* Modified to run under the MINIX operating system by Don Cope */
  14. /* These changes are also released into the public domain.      */
  15. /*                             900906  */
  16. /****************************************************************/
  17.  
  18. #include <curses.h>
  19. #include "curspriv.h"
  20.  
  21. /****************************************************************/
  22. /* Newline() does line advance and returns the new cursor line.    */
  23. /* If error, return -1.                        */
  24. /****************************************************************/
  25.  
  26. static    short    newline(win, lin)
  27.   WINDOW    *win;
  28.   short      lin;
  29.   {
  30.   if (++lin > win->_regbottom)
  31.     {
  32.     lin--;
  33.     if (win->_scroll)
  34.       scroll(win);
  35.     else
  36.       return(-1);
  37.     } /* if */
  38.   return(lin);
  39.   } /* newline */
  40.  
  41. /****************************************************************/
  42. /* Waddch() inserts character 'c' at the current cursor posi-    */
  43. /* tion in window 'win', and takes any actions as dictated by    */
  44. /* the character.                        */
  45. /****************************************************************/
  46.  
  47. int waddch(win, c)
  48.   register WINDOW    *win;
  49.   char             c;
  50.   {
  51.   short    x = win->_curx;
  52.   short    y = win->_cury;
  53.   short    newx;
  54.   int    ch = c;
  55.   int      ts = win->_tabsize;
  56.  
  57.   ch &= 0xff;            /* kill any sing-extend */
  58.   if (y > win->_maxy  ||  x > win->_maxx  ||  y < 0  ||  x < 0)
  59.     return(ERR);
  60.   switch (ch)
  61.     {
  62.     case '\t':    for (newx = ((x/ts) + 1) * ts; x < newx; x++)
  63.           {
  64.           if (waddch(win, ' ') == ERR)
  65.             return(ERR);
  66.           if (win->_curx == 0)        /* if tab to next line */
  67.             return(OK);            /* exit the loop */
  68.           } /* for */
  69.         return(OK);
  70.     case '\n':    if (_cursvar.autocr && !(_cursvar.raw)) /* if lf -> crlf */
  71.           x = 0;
  72.         if ((y = newline(win, y)) < 0)
  73.           return(ERR);
  74.         break;
  75.     case '\r':    x = 0;
  76.         break;
  77.     case '\b':
  78.         if (--x < 0)    /* no back over left margin */
  79.                   x = 0;
  80.         if (win->_minchng[y] == _NO_CHANGE)
  81.         {
  82.               win->_minchng[y] = x-1;
  83.             win->_maxchng[y] = x+1;
  84.         }
  85.         else
  86.             if (x < win->_minchng[y])
  87.                 win->_minchng[y] = x-1;
  88.             else
  89.                 if (x > win->_maxchng[y])
  90.                     win->_maxchng[y] = x+1;
  91.         break;
  92.     case 0x7f:    if (waddch(win,'^') == ERR)
  93.           return(ERR);
  94.         return(waddch(win,'?'));
  95.     default:    if (ch < ' ')            /* handle control chars */
  96.           {
  97.           if (waddch(win,'^') == ERR)
  98.             return(ERR);
  99.           return(waddch(win,c + '@'));
  100.           } /* if */
  101.         ch |= (win->_attrs & ATR_MSK);
  102.         if (win->_line[y][x] != ch)    /* only if data change */
  103.           {
  104.           if (win->_minchng[y] == _NO_CHANGE)
  105.             win->_minchng[y] = win->_maxchng[y] = x;
  106.           else
  107.             if (x < win->_minchng[y])
  108.               win->_minchng[y] = x-1;
  109.             else
  110.               if (x > win->_maxchng[y])
  111.             win->_maxchng[y] = x+1;
  112.           } /* if */
  113.         win->_line[y][x++] = ch;
  114.         if (x > win->_maxx)        /* wrap around test */
  115.           {
  116.           x = 0;
  117.           if ((y = newline(win, y)) < 0)
  118.             return(ERR);
  119.           } /* if */
  120.         break;
  121.     } /* switch */
  122.   win->_curx = x;
  123.   win->_cury = y;
  124.   return(OK);
  125.   } /* waddch */
  126.  
  127. /****************************************************************/
  128. /* Addch() inserts character 'c' at the current cursor posi-    */
  129. /* tion in stdscr, and takes any actions as dictated by the    */
  130. /* character.                            */
  131. /****************************************************************/
  132.  
  133. int addch(c)
  134.   char     c;
  135.   {
  136.   return (waddch(stdscr,c));
  137.   } /* addch */
  138.  
  139. /****************************************************************/
  140. /* Mvaddch() moves to position in stdscr, then inserts charac-    */
  141. /* ter 'c' at that point, and takes any actions as dictated by    */
  142. /* the character.                        */
  143. /****************************************************************/
  144.  
  145. int mvaddch(y,x,c)
  146.   int     x;
  147.   int     y;
  148.   char     c;
  149.   {
  150.   if (wmove(stdscr,y,x) == ERR)
  151.     return(ERR);
  152.   return (waddch(stdscr,c));
  153.   } /* mvaddch */
  154.  
  155. /****************************************************************/
  156. /* Mvwaddch() moves to position in window 'win', then inserts    */
  157. /* character 'c' at that point in the window, and takes any    */
  158. /* actions as dictated by the character.            */
  159. /****************************************************************/
  160.  
  161. int mvwaddch(win,y,x,c)
  162.   WINDOW *win;
  163.   int      x;
  164.   int      y;
  165.   char      c;
  166.   {
  167.   if (wmove(win,y,x) == ERR)
  168.     return(ERR);
  169.   return (waddch(win,c));
  170.   } /* mvwaddch */
  171.